package com.top.ruizhong.main.video

import android.app.Activity
import android.content.Intent
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction
import com.module.lemlin.base.BaseAbstractActivity
import com.top.ruizhong.R
import kotlinx.android.synthetic.main.activity_camera_preview.*


class CameraActivity : BaseAbstractActivity() {

    companion object {
        fun open(activity: Activity) {
            val intent = Intent(activity, CameraActivity::class.java)
            activity.startActivity(intent)
        }
    }

    override fun stateBar(): StatusBar {
        return StatusBar(
            isLightMode = false,
            color = R.color.colorBlack,
            bottomColor = R.color.colorBlack,
            view = mCardView
        )
    }

    override val layoutResId: Int
        get() = R.layout.activity_camera_preview

    override fun initView() {
        supportFragmentManager(CameraScreenFragment {
            val pathVideo: String = it.savedUri?.path ?: return@CameraScreenFragment
            supportFragmentManager(CameraPlayFragment.newInstance(pathVideo))
        }, isToBackStack = false)
    }

    private fun supportFragmentManager(fragment: Fragment, isToBackStack: Boolean = true) {
        val transaction: FragmentTransaction = supportFragmentManager.beginTransaction()
        if (isToBackStack) {
//            transaction.setCustomAnimations(
//                R.animator.slide_right_in, R.animator.slide_left_out,
//                R.animator.slide_left_in, R.animator.slide_right_out
//            )
            transaction.add(R.id.flCameraPreview, fragment)
            transaction.addToBackStack(null)
        } else {
            transaction.add(R.id.flCameraPreview, fragment)
        }
        transaction.commit()
    }

}